// pages/grid3_guide.js
const getGuidenceFilesByKeyword = require('../../utils/API').getGuidenceFilesByKeyword
Page({
	data: {
		keyword: '',
		fileList: []
	},
	onLoad() {

	},
	bindKeywordInput(e){
		this.setData({
			keyword:e.detail.value
		})
	},
	// 点击文件时  打开文件
	bindTapFile(e) {
		let link = e.target.dataset.link
		wx.downloadFile({
			url: link,
			success: function (res) {
				const filePath = res.tempFilePath
				wx.openDocument({
					filePath,
					success: function (res) {
						console.log('打开文档成功')
					}
				})
			},
			fail() {
				wx.showToast({
					title: '打开文件失败',
					icon: 'none'
				})
			}
		})
	},
	// 点击搜索按钮
	bindSearchButtonTap() {
		getGuidenceFilesByKeyword(this.data.keyword).then(files=>{
		    this.setData({
		        fileList:files
		    })
		},e=>{
			wx.showToast({
				title: '网络请求错误',
				icon:'none'
			})
		})
	}
})